/**
 * Copyright (C) 2025 pony working team
 * SPDX-License-Identifier: MulanPSL-2.0
 */

/* define to prevent recursive inclusion -------------------------------------*/
#ifndef __PONY_HAL_LCD_H__
#define __PONY_HAL_LCD_H__

/* includes (standard library, system) ---------------------------------------*/
/* includes (other library) --------------------------------------------------*/
/* includes (project) --------------------------------------------------------*/
/* includes (local) ----------------------------------------------------------*/
#include "hal.h"

#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */

/* defines -------------------------------------------------------------------*/
/* typedefs ------------------------------------------------------------------*/

/* ioctl cmds */
enum hal_lcd_cmd {
    /* ioctl(lcd, cmd, uint32_t) */
    HAL_LCD_CMD_RESET_CTRL,
    HAL_LCD_CMD_BLK_CTRL,
    /* ioctl(lcd, cmd) */
    HAL_LCD_CMD_BLK_TOGGLE,
    /* expand */
    HAL_LCD_CMD_CUSTOM,
};

typedef struct hal_lcd hal_lcd_t;

typedef struct hal_lcd_methods {
    int (*init)(hal_lcd_t *lcd);
    int (*setpixel)(hal_lcd_t *lcd, uint32_t x, uint32_t y, uint32_t color);
    int (*ioctl)(hal_lcd_t *lcd, int, va_list);
} hal_lcd_methods_t;

struct hal_lcd {
    hal_dev_t parent;
    const hal_lcd_methods_t *methods;
};

/* macro ---------------------------------------------------------------------*/
/* inlines -------------------------------------------------------------------*/
/* externs -------------------------------------------------------------------*/

extern hal_lcd_t *hal_lcd_open(const char *name);
extern int hal_lcd_setpixel(hal_lcd_t *lcd, uint32_t x, uint32_t y, uint32_t color);
extern int hal_lcd_ioctl(hal_lcd_t *lcd, int cmd, ...);
extern int hal_lcd_fill(hal_lcd_t *lcd, uint32_t x1, uint32_t y1, uint32_t w, uint32_t h,
                        uint32_t color);
extern int hal_lcd_draw_point(hal_lcd_t *lcd, uint32_t x, uint32_t y, uint32_t color);
extern int hal_lcd_draw_line(hal_lcd_t *lcd, uint32_t x1, uint32_t y1, uint32_t x2, uint32_t y2,
                             uint32_t color);
extern int hal_lcd_draw_rect(hal_lcd_t *lcd, uint32_t x1, uint32_t y1, uint32_t w, uint32_t h,
                             uint32_t color);
extern int hal_lcd_draw_circle(hal_lcd_t *lcd, uint32_t x0, uint32_t y0, uint8_t r, uint32_t color);
extern int hal_lcd_register(hal_lcd_t *lcd, const char *name, const hal_lcd_methods_t *methods,
                            uintptr_t data);

#ifdef __cplusplus
}
#endif /* __cplusplus */

#endif /* __PONY_HAL_LCD_H__ */
